/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package eproject_sem2;

import java.awt.Color;
import java.awt.Component;
import javax.swing.JInternalFrame;
import javax.swing.JTable;


/**
 *
 * @author h
 */
public class courier extends javax.swing.JFrame {
    ConnectSQL a=new ConnectSQL();
    VotesSent_Sever s= new VotesSent_Sever();
   static String SB=null;

    public static String getSB() {
        return SB;
    }

    public JInternalFrame getItnfCourier() {
        return itnfCourier;
    }
     
    /**
     * Creates new form courier
     */
    public courier() {
        initComponents();
        a.ShowTable(tableListBill,"","Waybill","Date","StatusTT","StatusVH","EmployeeIDGN","EmployeeIDKT","All","All","All");
        
 
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        itnfCourier = new javax.swing.JInternalFrame();
        jPListBill = new javax.swing.JPanel();
        cBoxStt = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        cBoxDay = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        btnView = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        tableListBill = new javax.swing.JTable();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        cBoxYear = new javax.swing.JComboBox();
        cBoxMonth = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        jPChangeStt = new javax.swing.JPanel();
        txtIdChange = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        cBoxSttChange = new javax.swing.JComboBox();
        BtnSttChange = new javax.swing.JButton();
        btnShowBill = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        itnfCourier.setClosable(true);
        itnfCourier.setVisible(true);

        jPListBill.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Display Information"));

        cBoxStt.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "ALL", "Still", "Pending", "Complete" }));
        cBoxStt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cBoxSttActionPerformed(evt);
            }
        });

        jLabel1.setText("Chose status:");

        cBoxDay.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "All", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "" }));

        jLabel2.setText("Chose time:");

        btnView.setText("View");
        btnView.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnViewActionPerformed(evt);
            }
        });

        tableListBill.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        tableListBill.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tableListBillMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tableListBill);

        jScrollPane2.setViewportView(jScrollPane1);

        jLabel4.setText("Day:");

        jLabel5.setText("Month:");

        cBoxYear.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "All", "2013", "2012", "2011", "2010", "2009", "2008" }));
        cBoxYear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cBoxYearActionPerformed(evt);
            }
        });

        cBoxMonth.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "All", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "" }));
        cBoxMonth.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cBoxMonthActionPerformed(evt);
            }
        });

        jLabel6.setText("Year:");

        javax.swing.GroupLayout jPListBillLayout = new javax.swing.GroupLayout(jPListBill);
        jPListBill.setLayout(jPListBillLayout);
        jPListBillLayout.setHorizontalGroup(
            jPListBillLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPListBillLayout.createSequentialGroup()
                .addGroup(jPListBillLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPListBillLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel1)
                        .addGap(28, 28, 28)
                        .addComponent(cBoxStt, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 59, Short.MAX_VALUE)
                        .addComponent(jLabel2)
                        .addGap(29, 29, 29)
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(cBoxDay, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel5)
                        .addGap(18, 18, 18)
                        .addComponent(cBoxMonth, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(cBoxYear, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btnView, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane2))
                .addContainerGap())
        );
        jPListBillLayout.setVerticalGroup(
            jPListBillLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPListBillLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPListBillLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cBoxStt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1)
                    .addComponent(cBoxDay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5)
                    .addComponent(cBoxMonth, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6)
                    .addComponent(btnView, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cBoxYear, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(31, 31, 31)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 187, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(67, Short.MAX_VALUE))
        );

        jPChangeStt.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Update Status"));

        txtIdChange.setEditable(false);

        jLabel3.setText("Bill ID:");

        cBoxSttChange.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Still", "Pending", "Completed", " " }));

        BtnSttChange.setText("OK");
        BtnSttChange.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtnSttChangeActionPerformed(evt);
            }
        });

        btnShowBill.setText("Show Bill");
        btnShowBill.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnShowBillActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPChangeSttLayout = new javax.swing.GroupLayout(jPChangeStt);
        jPChangeStt.setLayout(jPChangeSttLayout);
        jPChangeSttLayout.setHorizontalGroup(
            jPChangeSttLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPChangeSttLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPChangeSttLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPChangeSttLayout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(btnShowBill))
                    .addGroup(jPChangeSttLayout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addGap(45, 45, 45)
                        .addComponent(txtIdChange, javax.swing.GroupLayout.DEFAULT_SIZE, 193, Short.MAX_VALUE)))
                .addGap(88, 88, 88)
                .addComponent(cBoxSttChange, javax.swing.GroupLayout.PREFERRED_SIZE, 184, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(40, 40, 40)
                .addComponent(BtnSttChange, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(58, 58, 58))
        );
        jPChangeSttLayout.setVerticalGroup(
            jPChangeSttLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPChangeSttLayout.createSequentialGroup()
                .addGroup(jPChangeSttLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPChangeSttLayout.createSequentialGroup()
                        .addGap(28, 28, 28)
                        .addGroup(jPChangeSttLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtIdChange, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cBoxSttChange, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(BtnSttChange, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnShowBill))
                    .addGroup(jPChangeSttLayout.createSequentialGroup()
                        .addGap(37, 37, 37)
                        .addComponent(jLabel3)))
                .addContainerGap(44, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout itnfCourierLayout = new javax.swing.GroupLayout(itnfCourier.getContentPane());
        itnfCourier.getContentPane().setLayout(itnfCourierLayout);
        itnfCourierLayout.setHorizontalGroup(
            itnfCourierLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(itnfCourierLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(itnfCourierLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(itnfCourierLayout.createSequentialGroup()
                        .addComponent(jPListBill, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, itnfCourierLayout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jPChangeStt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(48, 48, 48))))
        );
        itnfCourierLayout.setVerticalGroup(
            itnfCourierLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(itnfCourierLayout.createSequentialGroup()
                .addComponent(jPListBill, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPChangeStt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(28, Short.MAX_VALUE))
        );

        jPChangeStt.getAccessibleContext().setAccessibleName("Change bill status");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(itnfCourier, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(itnfCourier, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void BtnSttChangeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnSttChangeActionPerformed
        // TODO add your handling code here:
        int sttchange=cBoxSttChange.getSelectedIndex();
        String idChange=txtIdChange.getText();
        String st=null;
        
        try{
        ConnectSQL con=new ConnectSQL();       
       if(sttchange==0)                              
            st="UPDATE List_VotesSent SET StatusVH='Still', EmployeeIDGN='"+s.GetID(Interface.EN, "Employee")+"'  WHERE Waybill='"+idChange+"'";
       if(sttchange==1)
           st="UPDATE List_VotesSent SET StatusVH='Pending', EmployeeIDGN='"+s.GetID(Interface.EN, "Employee")+"' WHERE Waybill='"+idChange+"'";
       if(sttchange==2)
           st="UPDATE List_VotesSent SET StatusVH='Complete', EmployeeIDGN='"+s.GetID(Interface.EN, "Employee")+"' WHERE Waybill='"+idChange+"'";                                            
                con.updateData(st);
        String i = (String) cBoxStt.getSelectedItem();
        if ("All".equalsIgnoreCase(i)) {
            a.ShowTable(tableListBill, "", "Waybill", "Date", "StatusTT", "StatusVH", "EmployeeIDGN", "EmployeeIDKT", (String) cBoxDay.getSelectedItem(), (String) cBoxMonth.getSelectedItem(), (String) cBoxYear.getSelectedItem());
        } else {
            a.ShowTable(tableListBill, "Where StatusVH='" + i + "'", "Waybill", "Date", "StatusTT", "StatusVH", "EmployeeIDGN", "EmployeeIDKT", (String) cBoxDay.getSelectedItem(), (String) cBoxMonth.getSelectedItem(), (String) cBoxYear.getSelectedItem());
        }
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        
        
       
        
    }//GEN-LAST:event_BtnSttChangeActionPerformed

    private void btnViewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnViewActionPerformed
        // TODO add your handling code here: 
       String i = (String) cBoxStt.getSelectedItem();
        if ("All".equalsIgnoreCase(i)) {
            a.ShowTable(tableListBill, "", "Waybill", "Date", "StatusTT", "StatusVH", "EmployeeIDGN", "EmployeeIDKT", (String) cBoxDay.getSelectedItem(), (String) cBoxMonth.getSelectedItem(), (String) cBoxYear.getSelectedItem());
        } else {
            a.ShowTable(tableListBill, "Where StatusVH='" + i + "'", "Waybill", "Date", "StatusTT", "StatusVH", "EmployeeIDGN", "EmployeeIDKT", (String) cBoxDay.getSelectedItem(), (String) cBoxMonth.getSelectedItem(), (String) cBoxYear.getSelectedItem());
        }
   
    }//GEN-LAST:event_btnViewActionPerformed

    private void cBoxSttActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cBoxSttActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cBoxSttActionPerformed

    private void tableListBillMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tableListBillMouseClicked
        // TODO add your handling code here:
        
        txtIdChange.setText((String)tableListBill.getValueAt(tableListBill.getSelectedRow(), 0));
    }//GEN-LAST:event_tableListBillMouseClicked

    private void cBoxMonthActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cBoxMonthActionPerformed
        // TODO add your handling code here:
       int a= cBoxMonth.getSelectedIndex();
       if(a==0||a==2||a==4||a==6||a==7||a==9||a==11)
       {
           for(;cBoxDay.getItemCount()!=31;)
           {
               cBoxDay.addItem(cBoxDay.getItemCount()+1);
           }
       }
       if(a==1)
       {
           for(;cBoxDay.getItemCount()!=29;)
           {
               cBoxDay.removeItemAt(cBoxDay.getItemCount()-1);
           }
       }
       if(a==3||a==5||a==8||a==10)
       {
           for(;cBoxDay.getItemCount()!=33;)
           {
              int i=cBoxDay.getItemCount()+1;
               cBoxDay.addItem(i);
           }
           for(;cBoxDay.getItemCount()!=31;)
           {
               cBoxDay.removeItemAt((cBoxDay.getItemCount()-1));
           }
           
       }
       
       
    }//GEN-LAST:event_cBoxMonthActionPerformed

    private void cBoxYearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cBoxYearActionPerformed
        // TODO add your handling code here:

    }//GEN-LAST:event_cBoxYearActionPerformed

    private void btnShowBillActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnShowBillActionPerformed
        // TODO add your handling code here:
        SB="Where Waybill='"+txtIdChange.getText()+"'";
       new  Show_VotesSent().setVisible(true);
    }//GEN-LAST:event_btnShowBillActionPerformed

    /**
     * @param args the command line arguments
     */
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BtnSttChange;
    private javax.swing.JButton btnShowBill;
    private javax.swing.JButton btnView;
    private javax.swing.JComboBox cBoxDay;
    private javax.swing.JComboBox cBoxMonth;
    private javax.swing.JComboBox cBoxStt;
    private javax.swing.JComboBox cBoxSttChange;
    private javax.swing.JComboBox cBoxYear;
    private javax.swing.JInternalFrame itnfCourier;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPChangeStt;
    private javax.swing.JPanel jPListBill;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable tableListBill;
    private javax.swing.JTextField txtIdChange;
    // End of variables declaration//GEN-END:variables
}
